#ifndef MPURL_H
#define MPURL_H

#include <string>

/******************************
 *
 * 名称：      Http请求Url类
 * 用途：      定义Http Url相关属性与方法。
 * 作用范围：   公共的
 * 创建时间：   2022-10-03
 *
 ******************************/

namespace MP{
namespace HTTP{

bool checkIsUseHttps(const std::string & schema);

class Url
{
public:

    explicit Url(const std::string & url);

    Url(const Url & baseUrl,
        const std::string & relativeUri);

    Url(const std::string & schema,
        const std::string & host,
        unsigned short port,
        const std::string & relativeUri);

    //拷贝构造函数
    Url(const Url & c);

public:

    void setBaseUrl(const std::string & url);
    void setData(const std::string & schema,
                 const std::string & host,
                 unsigned short port,
                 const std::string & relativeUri = "/");

    void setScheme(const std::string& scheme);
    void setHost(const std::string& host);
    void setPort(unsigned short port);
    void setRelativeUri(const std::string& relativeUri);

    bool isUseHttps() const {
        return checkIsUseHttps(_schema);
    }

    const std::string& getScheme() const{
        return _schema;
    }

    const std::string& getHost() const{
        return _host;
    }

    unsigned short getPort() const{
        return _port;
    }


    const std::string& getRelativeUri() const{
        return _relativeUri;
    }

    std::string toString() const;

protected:
    void parseUrl(const std::string & url);
    void setHostAndPort(const std::string & strDomain);

private:
    std::string _schema;
    std::string _host;
    unsigned short _port;
    std::string _relativeUri;
};

}   //HTTP
}   //MP


#endif // MPURL_H
